package com.icloud.article.boot.controller.im;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.icloud.article.boot.dto.*;
import com.icloud.article.boot.service.IMService;
import com.icloud.article.boot.service.ITIMInviteMessageService;
import com.icloud.article.boot.vo.*;
import com.icloud.common.core.api.CommonResult;
import io.github.doocs.im.model.response.MemberResultItem;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "IM 接口")
@RequestMapping("/app/im")
@RequiredArgsConstructor
public class IMControler {
    @Autowired
    private IMService imService;
    @Autowired
    private ITIMInviteMessageService itimInviteMessageService;

    @ApiOperation("获取Tencent IM参数")
    @PostMapping("/tencent/getImParams")
    @ResponseBody
    public CommonResult<IMParamsVo> getImParams(@Validated @RequestBody GetImParamsDto dto){
        return CommonResult.success(imService.getImParams(dto));
    }

    @ApiOperation("搜索群组")
    @PostMapping("/tencent/searchGroup")
    @ResponseBody
    public CommonResult<IMGroupListVo> searchGroup(@Validated @RequestBody SearchGroupDto dto){
        return CommonResult.success(imService.searchGroup(dto));
    }

    @ApiOperation("发送单聊消息")
    @PostMapping("/tencent/sendSingleMessage")
    @ResponseBody
    public CommonResult<String> sendSingleMessage(@Validated @RequestBody SendSingleMessageDto dto){
        return CommonResult.success(imService.sendSingleMessage(dto));
    }

    @ApiOperation("批量发送单聊消息")
    @PostMapping("/tencent/sendBatchSingleMessage")
    @ResponseBody
    public CommonResult<SendBatchSingleMessageVo> sendBatchSingleMessage(@Validated @RequestBody SendBatchSingleMessageDto dto){
        return CommonResult.success(imService.sendBatchSingleMessage(dto));
    }

    @ApiOperation("添加好友-搜索用户资料")
    @PostMapping("/tencent/searchCustomer")
    @ResponseBody
    public CommonResult<SearchCustomerVo> searchCustomer(@Validated @RequestBody SearchCustomerDto dto){
        return CommonResult.success(imService.searchCustomer(dto));
    }

    @ApiOperation("邀请好友/入群")
    @PostMapping("/tencent/invite")
    @ResponseBody
    public CommonResult<Boolean> invite(@Validated @RequestBody IMBatchInviteDto dto){
        return CommonResult.success(itimInviteMessageService.invite(dto));
    }

    @ApiOperation("处理邀请消息")
    @PostMapping("/tencent/invite/handle")
    @ResponseBody
    public CommonResult<Boolean> handle(@Validated @RequestBody IMInviteHandleDto dto){
        return CommonResult.success(itimInviteMessageService.handle(dto));
    }

    @ApiOperation("查询指定客户的邀请消息")
    @PostMapping("/tencent/invite/page")
    @ResponseBody
    public CommonResult<Page<IMInviteVo>> invitePage(@Validated @RequestBody IMInvitePageDto dto){
        return CommonResult.success(itimInviteMessageService.invitePage(dto));
    }

    @ApiOperation("添加群成员")
    @PostMapping("/tencent/group/member/add")
    @ResponseBody
    public CommonResult<List<MemberResultItem>> addGroupMember(@Validated @RequestBody IMAddGroupMemberDto dto){
        return CommonResult.success(imService.addGroupMember(dto));
    }

    @ApiOperation("收藏聊天消息")
    @PostMapping("/tencent/message/collect")
    @ResponseBody
    public CommonResult<Boolean> messageCollect(@Validated @RequestBody IMMessageCollectDto dto){
        return CommonResult.success(imService.messageCollect(dto));
    }
}
